$(document).ready(function() {
	// 菜系对应的菜品的数据绑定
	var foodVue = new Vue({
		el : '#showFoodDiv',
		data : {
			items : null
		},
		methods : {
			onclick : function(food) {
				showChooseFoodQuantityBox(food);
			}
		}
	});
	
	
	// 编辑菜品
	showFoodByClassId= function(classificationId) {
		getFoodByClassId(classificationId);
	};
	
	//搜索菜品
	$("#searchFoodButton").on("click", function() {
		var data={"searchWords":$("#inputSearchWords").val()};
		baseUtil.httpSend("food/getFoodByFoodNameOrPinyinAjax", data, setDataBySearch);
	});
	
	
	
	function setDataBySearch(data){
		Vue.set(foodVue, "items", data);
	}
	
	
	function showChooseFoodQuantityBox(food){
		var chooseFoodQuantityBox = layer.open({
			type : 2,
			maxmin : true,
			title : '选择菜品数量',
			area : [ '80%', '93%' ],
			btn : [ '确认', '取消' ] // 只是为了演示
			,
			yes : function() {
				// 获得子窗口的值
				var childBox = layer.getChildFrame('body', chooseFoodQuantityBox);
				
				var foodQuantity = childBox.find("#inputFoodQuantity").val();
				var mealTime = childBox.find("#chooseMealTime").val();
				var cookId = childBox.find("#chooseCook option:selected").val();
				var cookName = childBox.find("#chooseCook option:selected").text();
				
				var breakfast = $("#breakfastList").val();
				var lunch = $("#lunchList").val();
				var dinner = $("#dinnerList").val();
				var object={
						"foodId":  food.foodId  ,
						"foodName":  food.foodName  ,
						"foodQuantity":  foodQuantity  ,
						"unitName": food.unit.unitName,
						"productById":  cookId  ,
						"productByName": cookName   ,
						"productPrice": food.productPrice,
						"totalPrice": foodQuantity*(food.productPrice)
				};
				//处理早餐列表
				if (mealTime==1) {
					if (breakfast != "") {
						breakfast = eval('(' + breakfast + ')');
						breakfast.push(object);
					}else{
						breakfast=new Array();
						breakfast.push(object);
					}
					
					$("#breakfastList").val(JSON.stringify(breakfast));
				}
				//处理午餐列表
				else if (mealTime==2) {
					if (lunch != "") {
						lunch = eval('(' + lunch + ')');
						lunch.push(object);
					}else{
						lunch=new Array();
						lunch.push(object);
					}
					$("#lunchList").val(JSON.stringify(lunch));
				}
				
				//处理晚餐列表
				else if (mealTime==3) {
					if (dinner != "") {
						dinner = eval('(' + dinner + ')');
						dinner.push(object);
					}else{
						dinner=new Array();
						dinner.push(object);
					}
					$("#dinnerList").val(JSON.stringify(dinner));
				}
				
				layer.close(chooseFoodQuantityBox);
			},
			btn2 : function() {
				layer.close();
			},
			shadeClose : true, // 点击遮罩关闭
			content : SERVER_PRE_URL+'food/getFoodByPrimaryKeyNoMaterialReturnTo?foodId='+food.foodId+'&returnTo=chooseFoodQuantity'
		});
	}
	
	

	function getFoodByClassId(classificationId){
		var data={"classificationId":classificationId};
		baseUtil.httpSend("food/getFoodByClassificationIdAjax",data, setFoodVueData);
	}
	
	function setFoodVueData(data){
		Vue.set(foodVue, "items", data);
	}
	
	
	
});



